package com.cyz.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.admin.service.StudyResourceTypeIdService;
import com.cyz.admin.service.StudyResourceTypeService;
import com.cyz.common.bean.StudyResourceTypeId;
import com.cyz.common.mapper.StudyResourceTypeIdMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 34928
* @description 针对表【study_resource_type_id】的数据库操作Service实现
* @createDate 2023-02-22 19:51:54
*/
@Service
public class StudyResourceTypeIdServiceImpl extends ServiceImpl<StudyResourceTypeIdMapper, StudyResourceTypeId>
    implements StudyResourceTypeIdService {

    @Autowired
    private StudyResourceTypeService studyResourceTypeService;

    @Override
    public List<String> getTypeNamesByStudyResourceId(Integer id) {
        LambdaQueryWrapper<StudyResourceTypeId> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StudyResourceTypeId::getResourceId,id);
        List<StudyResourceTypeId> list = list(lambdaQueryWrapper);
        List<String> typeNames = new ArrayList<>();
        list.stream()
                .map(StudyResourceTypeId::getReosurceTypeId
                )
                .forEach(item -> {
            typeNames.add(studyResourceTypeService.getById(item).getName());
        });
        return typeNames;
    }

    @Override
    public List<Integer> getTypeIdsByStudyResourceId(Integer id) {
        LambdaQueryWrapper<StudyResourceTypeId> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StudyResourceTypeId::getResourceId,id);
        List<StudyResourceTypeId> list = list(lambdaQueryWrapper);
        List<Integer> typeIds = new ArrayList<>();
        list.stream()
                .map(StudyResourceTypeId::getReosurceTypeId
                )
                .forEach(item -> {
                    typeIds.add(studyResourceTypeService.getById(item).getId());
                });
        return typeIds;
    }
}




